/**
 * Software License Declaration.
 * <p>
 * wandaph.com, Co,. Ltd.
 * Copyright ? 2017 All Rights Reserved.
 * <p>
 * Copyright Notice
 * This documents is provided to wandaph contracting agent or authorized programmer only.
 * This source code is written and edited by wandaph Co,.Ltd Inc specially for financial
 * business contracting agent or authorized cooperative company, in order to help them to
 * install, programme or central control in certain project by themselves independently.
 * <p>
 * Disclaimer
 * If this source code is needed by the one neither contracting agent nor authorized programmer
 * during the use of the code, should contact to wandaph Co,. Ltd Inc, and get the confirmation
 * and agreement of three departments managers  - Research Department, Marketing Department and
 * Production Department.Otherwise wandaph will charge the fee according to the programme itself.
 * <p>
 * Any one,including contracting agent and authorized programmer,cannot share this code to
 * the third party without the agreement of wandaph. If Any problem cannot be solved in the
 * procedure of programming should be feedback to wandaph Co,. Ltd Inc in time, Thank you!
 */
package com.varton.service.impl;

import com.varton.registry.RegistryCenterImpl;
import com.varton.server.RpcServer;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author lihuazeng
 * @version Id: Server.java, v 0.1 2018/6/19 17:03 lihuazeng Exp $$
 */
public class Server {
    private static Map<String,String> objs = new HashMap<>();
    public static void main(String[] args) {
//        objs.put(HelloService.class.getName(),HelloServiceImpl.class.getName());
//        try {
//            ServerSocket serverSocket = new ServerSocket();
//            serverSocket.bind(new InetSocketAddress("127.0.0.1",888));
//            Socket socket = serverSocket.accept();
//
//            InputStream is = socket.getInputStream();
//            ObjectInputStream ois = new ObjectInputStream(is);
//            PackageData data = (PackageData) ois.readObject();
//            String className = objs.get(data.getParentClassName());
//            Class<?> clazz = Class.forName(className);
//            String methodName = data.getMethodName();
//            Class<?>[] types = new Class[data.getArgs().length];
//            for (int i =0; i< data.getArgs().length; i++){
//                types[i] = data.getArgs()[i].getClass();
//            }
//            Method method = clazz.getDeclaredMethod(methodName,types);
//            Object obj = method.invoke(clazz.newInstance(),data.getArgs());
//
//            OutputStream os = socket.getOutputStream();
//            ObjectOutputStream oos = new ObjectOutputStream(os);
//            oos.writeObject(obj);
//            oos.flush();
//
//            os.close();
//            oos.close();
//            is.close();
//            ois.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

        RpcServer server = new RpcServer(new RegistryCenterImpl());
        server.bindService(HelloServiceImpl.class);
        server.publish("127.0.0.1:888");
        System.out.println("success...");
    }
}